package com.agv.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.agv.core.objectDomain.DatosCampo;
import com.agv.core.util.UtileriaBD;

public class UpdateCampoGenericoAction extends Action {

	private UtileriaBD utileriaBD;

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		int numCampos = Integer.parseInt( request.getParameter("numCampos") );
		List<DatosCampo> campos = new ArrayList<DatosCampo>();
		DatosCampo campo = new DatosCampo();
		
		for (int i = 0; i < numCampos; i++) {
			
			campo = new DatosCampo();
			campo.setNombreCampo(request.getParameter("nombreCampo"+i));
			campo.setValorCampo(request.getParameter("valorCampo"+i));
			campo.setNombreTabla(request.getParameter("nombreTabla"+i));
			campo.setValorPK(request.getParameter("valorPK"+i));
			campo.setNombreCampo(request.getParameter("nombrePK"+i));
			campos.add(campo);
		}
		
		
		utileriaBD.updateCampos(campos);
		return null;
		
	}
	
	
	public void setUtileriaBD(UtileriaBD utileriaBD) {
		this.utileriaBD = utileriaBD;
	}

	
}
